package com.fuled.test.tool_config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hcy
 * 配置类，配置各个需要的bean
 */
@Configuration
public class ToolConfig {

    //请求头拦截器配置
    @Bean
    @ConditionalOnMissingBean(HeaderInterceptorPerformanceTool.class)
    public HeaderInterceptorPerformanceTool headerInterceptorPerformanceTool() {
        return new HeaderInterceptorPerformanceTool();
    }


    //获取用户名配置
    @Bean
    @ConditionalOnMissingBean(PerformanceUtilGetUserName.class)
    public PerformanceUtilGetUserName performanceUtilGetUserName() {
        return () -> "default";
    }

    //redis配置
    @Bean
    @ConditionalOnMissingBean(RedisConfigPerformanceTool.class)
    public RedisConfigPerformanceTool redisConfigPerformanceTool() {
        return new RedisConfigPerformanceTool();
    }

    //启动时执行配置
    @Bean
    @ConditionalOnMissingBean(StartupRunner.class)
    public StartupRunner startupRunner() {
        return new StartupRunner();
    }

    //web配置
    @Bean
    @ConditionalOnMissingBean(WebConfigPerformanceTool.class)
    public WebConfigPerformanceTool webConfigPerformanceTool() {
        return new WebConfigPerformanceTool();
    }

    //雪花算法
    /*@Bean
    @ConditionalOnMissingBean(IdGeneratorOptions.class)
    public WFGIdGenerator wfgIdGenerator() {
        //准备基础配置类，在此可以配置基础信息
        IdGeneratorOptions idGeneratorOptions = new IdGeneratorOptions();
        idGeneratorOptions.setWorkerId((short) 6); //设置机器码为6
        idGeneratorOptions.setWorkerIdBitLength((byte) 3); //设置机器码位长为3
        //装载id生成器的配置文件
        return new WFGIdGenerator(idGeneratorOptions);
    }*/
}
